﻿using BussinessObject.ObjectTwo;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ProjectHK3.App_Code;
using System.Data;
using DataAccess.ObjectTwo;
namespace ProjectHK3.Object_One
{
    public partial class City : System.Web.UI.Page
    {
        B_LoadGidAD ex = new B_LoadGidAD();
        B_AdminDetail fx = new B_AdminDetail();
        B_Delete sx = new B_Delete();
        B_Search bs = new B_Search();
        DataTable tb = new DataTable();
        D_GetAccount dg = new D_GetAccount();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                load();

            }
        }
        public void load()
        {
            Label5.Text = fx.getCity().ToString();
            GridView1.DataSource = ex.loadCity();
            GridView1.DataBind();
        }
        public void loadGR2()
        {
            _grwBranch.DataSource = bs.loadBranchCity(int.Parse(Session["Bran"].ToString()));
            _grwBranch.DataBind();
        }
        protected void _lbtDelete_Command(object sender, CommandEventArgs e)
        {
            if (e.CommandName == "delete")
            {

                Session["City"] = Convert.ToInt32(e.CommandArgument.ToString());
                if (sx.DeleteCity(Convert.ToInt32(e.CommandArgument.ToString())) == true)
                {
                    load();
                    Alert.Show("Delete Successful!!!");
                }
                else
                {
                    Alert.Show("You can't delete.Because it is being used.");
                }
            } 
            
        }

        protected void _lbtViewDetails_Command(object sender, CommandEventArgs e)
        {
            Session["City"] = Convert.ToInt32(e.CommandArgument.ToString());
            Response.Redirect("../Object One/CityDetail.aspx");
        }
        protected void _lbtViewBranch_Command(object sender, CommandEventArgs e)
        {
            Session["Bran"] = Convert.ToInt32(e.CommandArgument.ToString());
            loadGR2();
        }

        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            tb = dg.SearchCity(TextBox1.Text);
            GridView1.DataSource = tb;
            GridView1.DataBind();
            Label5.Text = tb.Rows.Count.ToString();
        }

        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            if (sx.DeleteCity(Convert.ToInt32(Session["City"].ToString())) == true)
            {
                Alert.Show("Delete Successful");
            }
            else
            {
                Alert.Show("you can not delete because it is being used ");
            }
        }

        protected void _grwBranch_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {

        }
    }
}